import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

class MyThreadPoolExecutor {
    private BlockingQueue<Runnable> queue;
    private int poolSize;
    private Thread[] executors;

    public MyThreadPoolExecutor(int poolSize) {
        this.poolSize = poolSize;
        executors = new Thread[poolSize];
        queue = new ArrayBlockingQueue<>(1000);

        for (int i = 0; i < poolSize; i++) {
            Thread t = new Thread(() -> {
                while(true) {
                    try {
                        queue.take().run();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
            executors[i] = t;
            t.start();
        }
    }

    public void submit(Runnable task) throws InterruptedException {
        queue.put(task);
    }
}

public class Demo4 {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPoolExecutor pool = new MyThreadPoolExecutor(10);
        for (int i = 0; i < 10000; i++) {
            int id = i;
            pool.submit(() -> {
                System.out.println("run" + id);
            });
        }
    }
}
